#pragma once

#include <assert.h>
#include <QColor>

namespace PBVP {
	/// 
	class Color {
	public:
		float r, g, b, a;


		/// Constructor
		/**
		*	default color set to black
		*/
		Color(float _r = 0, float _g = 0, float _b = 0, float _a = 1)
			:r(_r), g(_g), b(_b), a(_a)
		{}
		/// Constructor from QColor
		Color(const QColor& qc);

		/// 
		Color(float c[4]) {
			r = c[0]; g = c[1];
			b = c[2]; a = c[3];
		}

		/// Copy Constructor
		Color(const Color& color) 
		: r(color.r), g(color.g), b(color.b), a(color.a) {}
		
		/// assignment operator
		Color& operator=(const Color& c) {
			r = c.r; g = c.g;
			b = c.b; a = c.a;
			return *this;
		}
		
		/// comparison operator
		bool operator == (const Color& c) const {
			return(r == c.r && g == c.g && b == c.b && a == c.a);
		}
		
		///
		float operator[] (unsigned int n) {
			assert(n < 4);
			return *(&r+n);
		}

		/// Director pointer access		
		float* ptr() {return &r;}
		const float* ptr() const {return &r;}
		
		///
		QColor toQColor() const;

		/// convert to unsigned char representation of colors
		void toUChar4(unsigned char rgba[4]);

		/// Linear interpolation of color c1 and c2
		static Color linterp(const Color& c1, const Color& c2, float alpha);

		/// Some predefined colors
		static const Color COLOR_RED;
		static const Color COLOR_BLUE;
		static const Color COLOR_GREEN;
		static const Color COLOR_INDIAN_RED;
		static const Color COLOR_MAGENTA;
		static const Color COLOR_LIME_GREEN;
		static const Color COLOR_SLATE_GRAY;
		static const Color COLOR_SIENNA;
		static const Color COLOR_BLACK;
		static const Color COLOR_WHITE;			
	};
}